<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="css/regist.css">
    <link rel="stylesheet" type="text/css" href="font-awesome-4.7.0/css/font-awesome.min.css">
    <script type="text/javascript">

        var check_PN = false;     //手机号检测的flag
        var check_PS = false;     //密码检测的flag
        var check_CPS = false;    //确认密码检测的flag
        var check_EM = false;     //邮箱检测的flag
        var check_idcard = false; //检验身份证号
        var check_true = false;

        window.onload = function () {
            check_PN = false;
            check_PS = false;
            check_CPS = false;
            check_EM = false;
            check_idcard = false;
            check_truename = false;

            var formobj = document.getElementById("form");
            formobj.onsubmit = function () {
                if (check_PN == true && check_PS== true && check_CPS== true && check_EM== true &&check_idcard == true && check_truename == true) {
                    alert("注册成功！");
                    // window.location.href = "jsp/Login.jsp"
                    return true;
                } else {
                    alert("请正确填写全部信息！");
                    return false;
                }
            }

        }

        function onblur_phone() {
            var usernameobj = document.getElementById("phone");
            var usernameText = usernameobj.value;
            var patt_phone = /^1\d{10}$/;

            if (patt_phone.test(usernameText)) {
                check_PN = true;
            } else {
                alert("请输入正确格式的手机号！")
                check_PN = false;

            }
        }

        function onblur_truename() {
            var usernameobj = document.getElementById("truename");
            var usernameText = usernameobj.value;
            var patt_truename = /^[\u4E00-\u9FA5A-Za-z]+$/;

            if (patt_truename.test(usernameText)) {
                check_truename = true;
            } else {
                alert("只能输入中文和英文！")
                check_truename = false;

            }
        }

        function onblur_idcard() {
            var usernameobj = document.getElementById("idcard");
            var usernameText = usernameobj.value;
            var patt_idcard = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;

            if (patt_idcard.test(usernameText)) {
                check_idcard = true;
            } else {
                alert("请输入正确格式的身份证号！")
                check_idcard = false;

            }
        }

        function onblur_email() {
            var usernameobj = document.getElementById("email");
            var usernameText = usernameobj.value;
            var patt_email = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
            if (patt_email.test(usernameText)) {
                check_EM = true;
            } else {
                alert("请输入正确格式的邮箱！")
                check_EM = false;

            }
        }

        function onblur_password() {
            var passwordobj = document.getElementById("password");
            var passwordText = passwordobj.value;
            var patt = /^\w{5,12}$/;
            if (patt.test(passwordText)) {
                check_PS = true;
            } else {
                alert("密码由6到12位的字母数字下划线构成");
                check_PS = false;
            }
        }

        function onblur_confirm_password() {
            var passwordobj = document.getElementById("password");
            var passwordText = passwordobj.value;
            var confirm_passwordobj = document.getElementById("confirm_password");
            var confirm_passwordText = confirm_passwordobj.value;

            if (passwordText == confirm_passwordText) {
                check_CPS = true;
            } else {
                alert("请确认两次密码输入一致！")
                check_CPS = false;
            }
        }
    </script>
</head>
<body>
<table class="tablelist">
    <form action="regist_writerServlet" method="post" id="form">
        <tr>
            <th>昵称</th>
            <td><input type="text" name="nickname" id="nickname" class="inputtext" /></td>
        </tr>

        <tr>
            <th>姓名</th>
            <td><input type="text" name="truename" id="truename" class="inputtext" onblur="onblur_truename()"/></td>
        </tr>

        <tr>
            <th>身份证号</th>
            <td><input type="text" name="idcard" id="idcard" class="inputtext" onblur="onblur_idcard()"/></td>
        </tr>
        <tr>
            <th>手机号</th>
            <td><input type="text" name="phone" id="phone" class="inputtext" onblur="onblur_phone()"/></td>
        </tr>

        <tr>
            <th>密码</th>
            <td><input type="password" name="password" id="password" class="inputtext" onblur="onblur_password()"/></td>
        </tr>
        <tr>
            <th>确认密码</th>
            <td><input type="password" name="confire_password" id="confirm_password" class="inputtext"
                       onblur="onblur_confirm_password()"/></td>
        </tr>
        <tr>
            <th>邮箱</th>
            <td><input type="text" name="email" id="email" class="inputtext" onblur="onblur_email()"/></td>
        </tr>
        <tr>
            <th>性别</th>
            <td>
                <input type="radio" name="sex"  value="man">男
                <input type="radio" name="sex" value="woman">女
            </td>
        </tr>

        <tr>
            <th>提交按钮</th>
            <td><input type="submit" value="提交"></td>
        </tr>
        <th>重置按钮</th>
        <td><input type="reset" value="重置"></td>
        </tr>

    </form>
</table>

</body>
</html>



